#ifndef INTERSECTION_OF_TWO_SURFACES_H_
#define INTERSECTION_OF_TWO_SURFACES_H_

#include<Algorithm/threeD_elementary_geometry_tool_library.h>

#include<Mesh_IO/Mesh_IO.h>

#include<tool/libcell_tools_algorithm.h>

#include<Algorithm/fast_compute_maybe_intersecting_areas.h>

#define quote lib_cell_quote


#ifdef __cplusplus
extern "C" {
#endif

typedef struct SCrossover_Point
{//联合id
    template_v* v;
    template_f* f;
    template_c* c;
    double coordinates[3];

}SCrossover_Point;
typedef struct Crossover_Point {
    SCrossover_Point scp[2]; 
    void* prop;

}Crossover_Point;
static inline void crossover_point_init(Crossover_Point* cp)
{
    for(int i=0;i<2;i++)
    {
        cp->scp[i].c=NULL;
        cp->scp[i].v=NULL;
        cp->scp[i].f=NULL;
        memset(cp->scp[i].coordinates,0,sizeof(double)*3);
    } 
    cp->prop=NULL;
}
static inline void crossover_point_free(Crossover_Point* cp)
{
    free(cp);
}
typedef struct Mesh2_Crossover_Point{
    Int_RB_Tree* v2p,*f2p,*c2p;  
}Mesh2_Crossover_Point;
static inline void mesh2_crossover_point_init(Mesh2_Crossover_Point* mcp)
{
    mcp->v2p=(Int_RB_Tree*)malloc(sizeof(Int_RB_Tree));
    int_rb_tree_init(mcp->v2p);
    mcp->f2p=(Int_RB_Tree*)malloc(sizeof(Int_RB_Tree));
    int_rb_tree_init(mcp->f2p);
    mcp->c2p=(Int_RB_Tree*)malloc(sizeof(Int_RB_Tree));
    int_rb_tree_init(mcp->c2p);

}
void mesh2_crossover_point_free(Mesh2_Crossover_Point*mcp);



void get_intersection_lines_of_two_nodes(Mesh* curve,Node* n1,Node* n2,Mesh2_Crossover_Point* mcp1,Mesh2_Crossover_Point*mcp2);

Mesh* get_intersection_lines_of_two_nodesn(Node* n1,Node* n2,Mesh2_Crossover_Point*mcp1,Mesh2_Crossover_Point*mcp2);

//
// Mesh*  get_intersection_lines_of_two_nodesn(Node* n11,Node* n22,Mesh2_Crossover_Point*mcp1,Mesh2_Crossover_Point*mcp2);
// 
// mcp1储存m1到m(返回mesh)的信息
// mcp2储存m2到m(返回mesh)的信息

Mesh*  get_intersection_lines_of_two_meshs(Mesh* m1,Mesh* m2,Mesh2_Crossover_Point* mcp1,Mesh2_Crossover_Point*mcp2);


//
void adjust_mesh_topology_of_cintersecting_curve(Mesh* m,Mesh2_Crossover_Point*mcp1,Mesh2_Crossover_Point*mcp2);


#ifdef __cplusplus
}
#endif
#undef quote
#endif